
package com.huizhan.web.dao;
 
import org.springframework.data.domain.*;
import org.springframework.data.jpa.repository.*;
import org.springframework.stereotype.Repository;

import java.util.List;

import com.huizhan.web.model.*;

@Repository 
public interface TicketRecordDao extends JpaRepository<TicketRecord,Long>
{
    
    /**
     * 根据手机号码获取用户
     * @param project_Id 项目ID
     * @param phone 手机号码
     * @return 用户信息
     */
    List<Ticket> findByProjectIdAndPhone(String projectId,String phone);

    /**
     * 分页查赠票记录集合
     * @param name 名称
     * @param phone 手机号
     * @param ticket_Type_Id 票类型ID
     * @param project_Id 项目ID
     * @param type 类型
     * @param pageable 分页参数
     * @return 赠票记录集合
     */
    @Query(
        value = "SELECT * FROM ticket_record"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (phone LIKE CONCAT('%',?2,'%') OR ?2  = '' )"
            + " AND (project_Id =?3 OR ?3 = 0) "
            + " AND (ticket_Type_Id =?4 OR ?4 = 0 )"
            + " AND (type =?5 OR ?5 = 0 )", 
        countQuery = "SELECT COUNT(1) FROM ticket_record"
            + " WHERE (name LIKE CONCAT('%',?1,'%') OR ?1  = '')"
            + " AND (phone LIKE CONCAT('%',?2,'%') OR ?2  = '' )"
            + " AND (project_Id =?3 OR ?3 = 0) "
            + " AND (ticket_Type_Id =?4 OR ?4 = 0 )"
            + " AND (type =?5 OR ?5 = 0 )",
        nativeQuery = true
    )
    Page<TicketRecord> findByWhere(String name,String phone,String project_Id,Long ticket_Type_Id,Long type, Pageable  pageable);
}
